package com.comp6231.replica1.data;

import java.util.concurrent.atomic.AtomicInteger;

import com.comp6231.replica1.exception.InvalidRecordStatusException;

/**
 * 
 * @author sknarula (narula.sk@gmail.com)
 * @since September 2013
 *
 * This is an abstract Record class  
 */
public abstract class Record {
	/**
	 * Attributes to be used by all Records
	 */
	protected static volatile AtomicInteger nextRecordId = new AtomicInteger(10000);
	
	protected String recordId;
	private String firstName;
	private String lastName;
	private RecordType type;
	
	/** 
	 * Default constructor
	 */
	public Record() {
		
	}

	/** 
	 * Default constructor
	 */
	public Record(String firstName, String lastName, RecordType type) {
		this.firstName = firstName;
		this.lastName = lastName;
		this.type = type;
	}

	/**
	 * Getter and Setters
	 */
	
	public static AtomicInteger getNextRecordId() {
		return nextRecordId;
	}

	public static void setNextRecordId(AtomicInteger nextRecordId) {
		Record.nextRecordId = nextRecordId;
	}

	public String getRecordId() {
		return recordId;
	}

	public void setRecordId(String recordId) {
		this.recordId = recordId;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFistName(String fistName) {
		this.firstName = fistName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public RecordType getType() {
		return type;
	}

	public void setType(RecordType type) {
		this.type = type;
	}
	
	public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Record record = (Record) o;

        if (!recordId.equals(record.recordId)) return false;
        if (type != record.type) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = recordId.hashCode();
        result = 31 * result + (firstName != null ? firstName.hashCode() : 0);
        result = 31 * result + (lastName != null ? lastName.hashCode() : 0);
        result = 31 * result + (type != null ? type.hashCode() : 0);
        return result;
    }	
	
	
	// abstract method which must be implemented in each descendent
	public abstract void setStatus(String newStatus) throws InvalidRecordStatusException;
}
